<template>
  <div class="case">
    <na-table :datas.sync="tableData" :searchObj.sync="search" @updateDatas="getAllLists" @newAdd="newAddInstockBill">
    </na-table>
    <!--入库物料明细 -->
    <el-dialog title="入库物料明细" :visible.sync="isMarterdialog" :close-on-click-modal="false"
      custom-class="bodyNoPadDialog bigDialog" width="85%" @close="closeMarDialog">
      <div class="dialogDody marDialog flex flex_column">
        <div class="btnCon flex flex_end">
          <!--      搜索框-->
          <div class="search">
            <el-input v-model="materalSearch.likeWords" placeholder="输入关键字" size="small">
              <el-button slot="append" :loading="marLoading" type="primary" icon="el-icon-search" :disabled="marLoading"
                element-loading-spinner="el-icon-loading" @click="storageInfo">
                搜索
              </el-button>
            </el-input>
          </div>
        </div>
        <!-- 表格区域       -->
        <div class="tableCon">
          <el-table :data="materialList" border style="width: 100%">
            <el-table-column type="index" label="序号" width="55" />
            <el-table-column prop="stockGoodsCode" label="物料编号" min-width="110" />
            <el-table-column prop="stockGoodsName" label="物料名称" show-overflow-tooltip min-width="110" />
            <el-table-column prop="specificationName" label="规格型号" min-width="100" />
            <el-table-column prop="purchaseOrderNo" label="批次编码" min-width="100" />
            <el-table-column prop="groupName" label="物料分组" min-width="90" />
            <el-table-column prop="categoryName" label="物料类型" min-width="90" />
            <el-table-column prop="supplierName" label="供应商" min-width="90" />
            <el-table-column prop="goodsUnitName" label="物料单位" min-width="100" />
            <el-table-column prop="specificationJsValue" label="m²/每米" min-width="90" />
            <el-table-column prop="inStockQuantity" label="入库数量" min-width="90" />
            <el-table-column prop="inStockTatalSquare" label="入库平方数" min-width="110" />
            <el-table-column prop="stockGoodsPrice" label="入库单价" min-width="90" />
            <el-table-column prop="inStockSumValue" label="入库总金额" min-width="100" />
            <el-table-column prop="areaShelfName" label="入库库位" min-width="90" />
            <el-table-column prop="inStockBillNo" label="入库单号" min-width="90" />
            <el-table-column prop="warehouseName" label="入库仓库" min-width="90" />
            <el-table-column prop="inStockTypeName" label="入库类型" min-width="90" />
            <el-table-column prop="createDate" label="入库时间" min-width="90" />
            <el-table-column prop="inStockDesc" label="备注" min-width="150" show-overflow-tooltip />
          </el-table>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <!--    分页-->
        <div class="paginaCon noborder">
          <pagination :total="marTotale || 0" :page.sync="materalSearch.pageIndex" :limit.sync="materalSearch.pageSize"
            @pagination="storageInfo" />
        </div>
      </div>
    </el-dialog>
    <!-- 采购新建入库 -->
    <el-dialog :title="ops === 'modify' ? '编辑采购入库' : '新建采购入库'" :visible.sync="isAddPurDialog"
      :close-on-click-modal="false" custom-class="bodyNoPadDialog bigDialog" width="85%" @close="closeDialog">
      <div class="dialogDody">
        <div class="subTip">
          <span class="mr15"><span class="mr5">入库单号：</span>{{ inStockForm.inStockBillNo }}</span>
          <span class="mr15"><span
              class="mr5">创建日期：</span>{{ inStockForm.createTime || dayjs().format("YYYY-MM-DD") }}</span>
          <span><span class="mr5">创建人员：</span>{{ ops === "modify" ? purchaseForm.createorName : name }}</span>
        </div>
        <div class="addWuliaoBox">
          <el-form ref="inStockForm" :model="inStockForm" label-width="80px" label-position="left"
            class="dialogForm dialogInlineForm">
            <el-row>
              <el-col :span="8">
                <el-form-item label="入库类型" prop="inStockTypeName">
                  <el-input v-model="inStockForm.inStockTypeName" placeholder="入库类型" size="mini" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="关联单据" prop="associationBillNo">
                  <el-input v-model="inStockForm.associationBillNo" placeholder="关联单据" size="mini" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="采购人员" prop="associationBillNo">
                  <el-input v-model="inStockForm.extendData.purchasePersonName" placeholder="采购人员" size="mini"
                    disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="供应商" prop="extendData.supplierName">
                  <el-input v-model="inStockForm.extendData.supplierName" placeholder="采购人员" size="mini" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="采购备注" class="inlineText">
                  <el-input v-model="inStockForm.extendData.purchaseDesc" type="textarea" :rows="1" placeholder="采购备注"
                    size="mini" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="入库备注" class="inlineText">
                  <el-input v-model="inStockForm.inStockBillRemark" type="textarea" :rows="1" placeholder="入库备注"
                    size="mini" clearable />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <div class="tableBox">
            <div class="tt flex flex_between">
              <span class="fw">采购明细</span>
            </div>
            <el-table v-loading="searchLoading" :data="inStockBillDetailList" border style="width: 100%">
              <el-table-column label="物料编号" prop="stockGoodsCode" show-overflow-tooltip min-width="110" />
              <el-table-column label="物料类型" prop="categoryName" min-width="90" />
              <el-table-column label="供应商" prop="supplierName" show-overflow-tooltip min-width="90" />
              <el-table-column label="物料名称" prop="goodsName" show-overflow-tooltip min-width="110" />
              <el-table-column label="规格型号" prop="stockGoodsName" min-width="90" />
              <el-table-column label="库存数量" prop="stockQuantity" min-width="80" />
              <el-table-column label="采购数量" show-overflow-tooltip prop="planPurchaseQuantity" min-width="90" />
              <el-table-column label="到货数量" prop="purchaseQuantity" min-width="110" />
              <el-table-column
                  label="生产日期"
                  prop="dateOfManufacture"
                  min-width="150"
                >
                </el-table-column>
              <el-table-column label="物料单位" prop="goodsUnitName" min-width="80" />
              <el-table-column label="上次单价/米" prop="previousPrice" min-width="110" />
              <el-table-column label="单价/米" prop="purchasePrice" min-width="80" />
              <el-table-column label="换算数量" prop="specificationQuantity" min-width="90" />
              <el-table-column label="换算单位" show-overflow-tooltip prop="priceUnitName" min-width="100" />
              <el-table-column label="换算单价" show-overflow-tooltip prop="specificationPrice" min-width="100">
              </el-table-column>
              <el-table-column label="总金额" show-overflow-tooltip prop="totalAmount" min-width="100" />
              <el-table-column label="入库库位" show-overflow-tooltip prop="stockArea" min-width="150">
                <template slot-scope="{ row }">
                  <el-cascader v-model="row.stockArea" :show-all-levels="false" size="mini" :options="storageLocations"
                    :props="{ label: 'name', value: 'code' }" />
                </template>
              </el-table-column>
              <el-table-column label="备注" show-overflow-tooltip min-width="150">
                <template slot-scope="{ row }">
                  {{ row.purchaseDesc }}
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="isAddPurDialog = false">取 消</el-button>
        <!--  拒绝      -->
        <el-button :loading="addPurLoading" :disabled="addPurLoading" element-loading-spinner="el-icon-loading"
          type="warning" size="mini" @click="refuseClick">拒绝</el-button>
        <!-- 同意      -->
        <el-button :loading="addPurLoading" :disabled="addPurLoading" element-loading-spinner="el-icon-loading"
          type="primary" size="mini" @click="savaAdd">同意</el-button>
      </div>
    </el-dialog>
    <!-- 查看入库 -->
    <el-dialog title="查看入库" :visible.sync="isSeePurDialog" :close-on-click-modal="false"
      custom-class="bodyNoPadDialog bigDialog" width="85%" @close="closeDialog">
      <div class="dialogDody">
        <div class="subTip">
          <span class="mr15"><span class="mr5">入库单号：</span>{{ inStockForm.inStockBillNo }}</span>
          <span class="mr15"><span class="mr5">创建日期：</span>{{ inStockForm.createTime }}</span>
          <span><span class="mr5">创建人员：</span>{{ inStockForm.createPersonName }}</span>
        </div>
        <div class="addWuliaoBox">
          <el-form ref="inStockForm" :model="inStockForm" :rules="rules" label-width="80px" disabled
            label-position="left" class="dialogForm dialogInlineForm">
            <el-row>
              <el-col :span="8">
                <el-form-item label="入库类型" prop="inStockTypeName">
                  <el-input v-model="inStockForm.inStockTypeName" placeholder="申请公司" size="mini" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="关联单据" prop="associationBillNo">
                  <el-input v-model="inStockForm.associationBillNo" placeholder="关联单据" size="mini" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="采购人员" prop="associationBillNo">
                  <el-input v-model="inStockForm.extendData.purchasePersonName" placeholder="采购人员" size="mini"
                    disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="供应商" prop="extendData.supplierName">
                  <el-input v-model="inStockForm.extendData.supplierName" placeholder="采购人员" size="mini" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="采购备注" class="inlineText">
                  <el-input v-model="inStockForm.extendData.purchaseDesc" type="textarea" :rows="1" placeholder="采购备注"
                    size="mini" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="入库备注" class="inlineText">
                  <el-input v-model="inStockForm.inStockBillRemark" type="textarea" :rows="1" placeholder="入库备注"
                    size="mini" clearable />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <div class="tableBox">
            <div class="tt flex flex_between">
              <span class="fw">采购明细</span>
            </div>
            <el-table v-loading="searchLoading" :data="inStockBillDetailList" border style="width: 100%">
              <el-table-column label="物料编号" prop="stockGoodsCode" show-overflow-tooltip min-width="110" />
              <el-table-column label="物料类型" prop="categoryName" min-width="90" />
              <el-table-column label="供应商" prop="supplierName" show-overflow-tooltip min-width="90" />
              <el-table-column label="物料名称" prop="goodsName" show-overflow-tooltip min-width="110" />
              <el-table-column label="规格型号" prop="stockGoodsName" min-width="90" />
              <el-table-column label="库存数量" prop="stockQuantity" min-width="80" />
              <el-table-column label="采购数量" show-overflow-tooltip prop="planPurchaseQuantity" min-width="90" />
              <el-table-column label="到货数量" prop="purchaseQuantity" min-width="110" />
              <el-table-column label="物料单位" prop="goodsUnitName" min-width="80" />
              <el-table-column label="上次单价/米" prop="previousPrice" min-width="110" />
              <el-table-column label="单价/米" prop="inStockPrice" min-width="80" />
              <el-table-column label="换算数量" prop="specificationCount" min-width="90" />
              <el-table-column
                  label="生产日期"
                  prop="dateOfManufacture"
                  min-width="200"
                >
                </el-table-column>
              <el-table-column label="换算单位" show-overflow-tooltip prop="priceUnitName" min-width="100" />
              <el-table-column label="换算单价" show-overflow-tooltip prop="specificationPrice" min-width="100">
                <template slot-scope="scope">
                  {{ JSON.parse(scope.row.specificationPrice.toFixed(4)) }}
                </template>
              </el-table-column>
              <el-table-column label="总金额" show-overflow-tooltip prop="inStockValue" min-width="100">
                <template slot-scope="{row}">
                  <div v-if="row.isPriceUnit">
                    {{ row.specificationPrice*row.specificationCount }}
                  </div>
                  <div v-else>
                    {{ row.inStockValue }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="入库库位" show-overflow-tooltip prop="stockArea" min-width="120">
                <template slot-scope="{ row }">
                  {{ row.areaShelfName }}
                </template>
              </el-table-column>
              <el-table-column label="备注" show-overflow-tooltip prop="inStockRemark" min-width="150" />
            </el-table>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="isSeePurDialog = false">取 消</el-button>
        <!-- 查看入库     -->
        <el-button v-if="ops === 'see'" type="primary" size="mini" @click="isSeePurDialog = false">确定</el-button>
      </div>
    </el-dialog>
    <!-- 采购单明细 -->
    <el-dialog title="选择采购单" :visible.sync="isPurInfo" :close-on-click-modal="false"
      custom-class="bodyNoPadDialog bigDialog" width="85%">
      <div class="dialogDody">
        <!-- 搜索     -->
        <div class="btnCon flex flex_between" style="border-bottom: none">
          <!-- <div>
                       <el-radio-group v-model="purSearch.inStockState" size="mini" @change="getPurInfo">
                         <el-radio-button label="0">待入库</el-radio-button>
                         <el-radio-button label="1">部分入库</el-radio-button>
                         <el-radio-button label="-1">全部</el-radio-button>
                       </el-radio-group>
          </div> -->
          <!--      搜索框-->
          <div class="search">
            <el-input v-model="purSearch.likeWords" prefix-icon="el-icon-search" placeholder="输入关键字" size="small"
              @keyup.enter.native="getPurInfo">
              <!-- <el-button
                slot="append"
                :loading="purLoading"
                type="primary"
                icon="el-icon-search"
                :disabled="marLoading"
                element-loading-spinner="el-icon-loading"
                @click="getPurInfo"
              >
                搜索
              </el-button> -->
            </el-input>
          </div>
        </div>
        <!-- 表格区域       -->
        <div class="tableCon lastTdNoBorder pt0" style="padding: 16px">
          <el-table v-loading="purLoading" :data="purInfoLists" height="550" :row-class-name="tableRowClassName" border
            style="width: 100%">
            <el-table-column type="index" label="序号" align="center" width="50" />
            <el-table-column prop="purchaseOrderNo" label="采购单号" min-width="110" />
            <el-table-column prop="purchaseTypeName" label="采购类型" min-width="100" />
            <el-table-column prop="createTime" label="采购时间" show-overflow-tooltip min-width="110" />
            <el-table-column prop="detailCount" label="明细" min-width="100" />
            <el-table-column prop="totalCount" label="总数量" min-width="90" />
            <el-table-column prop="totalAmount" label="采购总金额" show-overflow-tooltip min-width="120" />
            <el-table-column prop="expectArrivalTime" label="期望到货日期" show-overflow-tooltip min-width="120" />
            <el-table-column prop="supplierName" label="供应商" sortable min-width="220" />
            <el-table-column prop="purchasePersonName" label="申请人员" min-width="90" />
            <el-table-column prop="purchaseDesc" label="备注" min-width="150" show-overflow-tooltip>
              <template scope="{row}">
                {{ row.purchaseDesc || "--" }}
              </template>
            </el-table-column>
            <el-table-column label="操作" width="100px" fixed="right" align="center">
              <template slot-scope="scope">
                <el-button type="text" size="medium" style="color: #606266" @click="confirmSelecd(scope.row)">
                  选择
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <!-- <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="isPurInfo=false">取 消</el-button>
        <el-button
          type="primary"
          size="mini"
          @click="confirmSelecd"
        >确定</el-button>
      </span> -->
    </el-dialog>
    <!-- 拒绝原因弹框   -->
    <el-dialog title="拒绝原因" :visible.sync="reasonVisible" :close-on-click-modal="false" custom-class="comDialog"
      append-to-body width="30%" @close="closeCancelDialog">
      <div class="dialogDody">
        <el-form ref="cancelForm" :model="cancelForm" :rules="rules" label-width="0px" class="dialogForm">
          <el-form-item label="" prop="stockStateDesc">
            <el-input v-model="cancelForm.stockStateDesc" type="textarea" :autosize="{ minRows: 2 }" placeholder="请输入内容"
              size="mini" clearable />
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="reasonVisible = false">取 消</el-button>
        <el-button v-loading="addLableLoading" :disabled="addLableLoading" element-loading-spinner="el-icon-loading"
          type="primary" size="mini" @click="refuseInstock">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import naTable from "@/components/naTable";
  import Pagination from "@/components/Pagination";
  import {
    arraySort
  } from "@/utils";
  import {
    mapGetters
  } from "vuex";
  export default {
    name: "Warehousing",
    components: {
      Pagination,
      naTable
    },
    computed: {
      ...mapGetters(["name"]),
    },
    data() {
      return {
        ops: "add", // 表格操作
        addLableLoading: false,
        reasonVisible: false, // 拒绝原因弹框是否显示
        addPurLoading: false,
        purLoading: false,
        radioSelect: null,
        isMarterdialog: false, // 入库物料明细
        isPurInfo: false, // 采购单明细
        isAddPurDialog: false, // 新建采购弹框是否打开
        isSeePurDialog: false, // 查看入库详情
        searchLoading: false, // 列表搜索加载效果
        marLoading: false, // 物料明细加载效果
        inStockForm: {
          inStockBillNo: "系统自动生成",
          inStockType: "采购入库",
          associationBillNo: "",
          warehouseCode: "",
          invoiceNumber: "",
          inStockBillRemark: "",
          backlashInStockBillNo: "",
          backlashRemark: "",
          extendData: {
            supplierName: "",
            purchasePersonName: "",
            purchaseDesc: "",
          },
          inStockBillDetailList: [],
        }, // 新建入库表单
        inStockBillDetailList: [], // 入库明细数据
        resetDataLists: [], // 入库明细数据重置数据
        purInfoLists: [], // 采购明细列表
        storageLocations: [], // 库位列表
        inStockID: null, // 入库单ID
        cancelForm: {
          stockStateDesc: "",
        }, // 拒绝表单
        // 入库搜索条件
        search: {
          QueryDataBaseFiled: '',
          pageIndex: 1,
          pageSize: 30,
          likeWords: "",
          inStockType: "",
        },
        total: 0,
        dataList: [], // 入库列表
        tableHead: [], // 入库表头
        tableHeight: null,
        warhouseList: [], // 仓库下拉列表数据
        materialList: [], // 物料明细列表
        materalSearch: {
          pageIndex: 1,
          pageSize: 30,
          likeWords: "",
        }, // 物料明细搜索条件
        purSearch: {
          likeWords: "",
          purchaseOrderState: 2, // 采购状态 (0 待确认/ 1 待到货/ 2 已到货/ -1 作废)。
          stockState: 0, // 库存状态(0 待入库/ 1 已入库/ -1 已拒绝)。
        }, // 采购单明细搜索条件
        marTotale: 0,
        currentRow: {},
        rules: {
          stockStateDesc: [{
            required: true,
            message: "请填写拒绝原因",
            trigger: "change"
          }, ],
        },

        tableData: {
          headId: 'head', //表头列显隐组件所需ID-避免多个页面id重复问题
          tableId: 'inStockID', //表格列表key,也就是一条数据的唯一标识
          senior: false, //高级搜索是否显示
          disableWord: '', //是否禁用显示的字段
          disableStatus: '', //判断未禁用的状态值
          // addTitle: '', //新建按钮名称-为''则不显示，为undefine则为新建
          addPermission: 'MenuCode5-2-1-1', //新建按钮权限
          addIcon: '', //新建按钮icon
          voidWord: '', //需要查询作废的字段
          statusList: [], //状态筛选条件列表
          statusWord: '', //状态筛选的字段
          refresh: true, //刷新按钮
          showSum: true, //显示合计
          //表格按钮
          operationBtn: [{
            title: '查看', //按钮名称
            methodsName: 'seeInsock', //按钮绑定方法的字段
          }],
          //表格内容
          tbody: [],
          //表格表头
          thead: [],
        },
      };
    },
    created() {
      // 采购列表表格头部
      this.getTableHead();
      // 获取仓库下拉列表
      this.getWarehouseList();
      // 库区库位
      this.getStorageLocations();
    },
    mounted() {},
    methods: {
      // 拒绝采购入库
      refuseInstock() {
        const params = {
          entityID: this.currentRow.purchaseID,
          stockStateDesc: this.cancelForm.stockStateDesc,
        };
        this.$refs.cancelForm.validate((valid) => {
          if (valid) {
            this.$api.warehouse.RefusePurchaseOrder(params).then(() => {
              this.$message({
                message: "已拒绝",
                type: "success",
              });
              this.reasonVisible = false;
              this.isAddPurDialog = false;
            });
          }
        });
      },
      // 拒绝采购入库点击事件
      refuseClick() {
        this.reasonVisible = true;
      },
      // 库区库位
      getStorageLocations() {
        const parmas = {
          warehouseCode: this.inStockForm.warehouseCode,
        };
        this.$api.warehouse.GetStockQueryAreaTreeView(parmas).then((res) => {
          this.storageLocations = res;
        });
      },
      // 入库单删除
      instockDelete(id) {
        const parmas = {
          entityID: id,
        };
        this.$confirm("确定删除该入库信息, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          this.$api.warehouse.DeleteInStockBill(parmas).then(() => {
            this.getAllLists();
            this.$message({
              message: "删除成功",
              type: "success",
            });
          });
        });
      },
      // 入库新建
      newAddInstockBill() {
        this.isPurInfo = true;
        // 采购单明细
        this.getPurInfo();
      },
      // 入库单详情
      getStockBillInfo(id) {
        const parmas = {
          queryBy: 1,
          queryValue: id,
        };
        this.$api.warehouse.GetSingleInStockBill(parmas).then((res) => {
          this.inStockForm = res;
          this.inStockForm.extendData = {
            supplierName: res.supplierName,
            purchasePersonName: res.purchasePersonName,
            purchaseDesc: res.purchaseDesc,
          };
          const arr = [...res.inStockBillDetailList];
          arr.forEach((item) => {
            const newArr = [];
            newArr.push(item.warehouseAreaCode, item.areaShelfCode);
            item.stockArea = newArr;
          });
          this.inStockBillDetailList = arr;
        });
      },
      // 编辑采购入库
      savaEidtAdd() {
        this.$refs.inStockForm.validate((valid) => {
          if (valid) {
            this.addPurLoading = true;
            let isvalid = true;
            this.inStockBillDetailList.forEach((item) => {
              item.warehouseAreaCode =
                (item.stockArea && item.stockArea[0]) || item.warehouseAreaCode;
              item.areaShelfCode =
                (item.stockArea && item.stockArea[1]) || item.areaShelfCode;
              if (item.stockArea.length < 1) {
                isvalid = false;
                return;
              }
            });
            if (!isvalid) {
              this.$message({
                message: "请选择入库库位",
                type: "warning",
              });
              return false;
            }
            this.inStockForm.inStockBillDetailList = this.inStockBillDetailList;
            const parmas = this.inStockForm;
            this.$api.warehouse
              .UpdateInStockBill(parmas)
              .then(() => {
                this.addPurLoading = false;
                this.isAddPurDialog = false;
                this.getAllLists();
                this.$message({
                  message: "编辑成功",
                  type: "success",
                });
              })
              .catch(() => {
                this.addPurLoading = false;
              });
          }
        });
      },
      // 新建入库
      savaAdd() {
        this.$refs.inStockForm.validate((valid) => {
          if (valid) {
            this.addPurLoading = true;
            let isvalid = true;
            this.inStockBillDetailList.forEach((item) => {
              if(item.stockArea){
                item.warehouseAreaCode = item.stockArea[0];
                item.areaShelfCode = item.stockArea[1];
                if (item.stockArea.length < 1) {
                  isvalid = false;
                  return;
                }
              }else{
                isvalid = false;
              }
            });
            console.log(isvalid);
            if (!isvalid) {
              this.$message({
                message: "请选择入库库位",
                type: "warning",
              });
              this.addPurLoading = false;
              return false;
            }
            this.inStockForm.inStockBillDetailList = this.inStockBillDetailList;
            const parmas = this.inStockForm;
            this.$api.warehouse
              .AddCGInStockBill(parmas)
              .then(() => {
                this.addPurLoading = false;
                this.isAddPurDialog = false;
                this.getAllLists();
                this.$message({
                  message: "新建成功",
                  type: "success",
                });
              })
              .catch(() => {
                this.addPurLoading = false;
              });
          }
        });
      },
      // 采购单明细
      getPurInfo() {
        const parmas = this.purSearch;
        this.purLoading = true;
        this.$api.warehouse
          .getRuKuPurInfo(parmas)
          .then((res) => {
            this.purInfoLists = res;
            this.purLoading = false;
          })
          .catch(() => {
            this.purLoading = false;
          });
      },
      // 给选中一行添加class
      tableRowClassName({
        row
      }) {
        if (this.currentRow.purchaseOrderNo === row.purchaseOrderNo) {
          return "selectd";
        }
      },
      // 查看采购入库
      seeInsock(data) {
        this.ops = "see";
        this.isSeePurDialog = true;
        this.getStockBillInfo(data.inStockID);
      },
      // 采购单明细选择确定
      confirmSelecd(row) {
        this.inStockBillDetailList = row.purchaseDetailsList;
        this.currentRow = row
        // this.resetDataLists = JSON.parse(JSON.stringify(newArr))
        this.inStockForm.associationBillNo = row.purchaseOrderNo;
        this.inStockForm.extendData.supplierName = row.supplierName;
        this.inStockForm.extendData.purchasePersonName = row.purchasePersonName;
        this.inStockForm.extendData.purchaseDesc = row.purchaseDesc;
        this.isAddPurDialog = true; // 打开新建采购入库弹框
        this.isPurInfo = false;
      },
      // 合计方法
      getSummaries(param) {
        const {
          columns,
          data
        } = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = "合计";
            return;
          }
          if (column.property === "inStockSumValue") {
            const values = data.map((item) => Number(item[column.property]));
            if (!values.every((value) => isNaN(value))) {
              sums[index] = values.reduce((prev, curr) => {
                const value = Number(curr);
                if (!isNaN(value)) {
                  return prev + curr;
                } else {
                  return prev;
                }
              }, 0);
              sums[index] = sums[index]++;
            } else {
              sums[index] = " ";
            }
          }
        });
        return sums;
      },
      // 入库物料明细
      storageInfo() {
        const parmas = this.materalSearch;
        this.marLoading = true;
        this.$api.warehouse
          .getStockGoodsInfo(parmas)
          .then((res) => {
            this.marLoading = false;
            this.materialList = res.list;
            this.marTotale = res.totalCount;
          })
          .catch(() => {
            this.marLoading = false;
          });
      },
      // 获取仓库下拉列表
      getWarehouseList() {
        this.$api.warehouse.getWarehouseList().then((res) => {
          this.warhouseList = res;
          this.search.warehouseCode = res[0].warehouseCode;
          this.inStockForm.warehouseCode = res[0].warehouseCode;
          // 入库列表
          this.getAllLists();
        });
      },
      // 采购列表表格头部
      getTableHead() {
        const parmas = {
          tableCode: this.$config.cgInStockBillList,
        };
        this.$api.common.getAllTableHead(parmas).then((res) => {
          res.sort(arraySort("columnSort"));
          this.tableData.thead = res;
        });
      },
      // 入库列表
      getAllLists() {
        const parmas = this.search;
        this.searchLoading = true;
        this.$api.warehouse
          .getWarehousingList(parmas)
          .then((res) => {
            this.tableData.tbody = res.list;
            this.search.total = res.totalCount;
            this.searchLoading = false;
          })
          .catch(() => {
            this.searchLoading = false;
          });
      },
      // 物料明细弹框关闭事件
      closeMarDialog() {
        this.materalSearch = this.$options.data().materalSearch;
      },
      // 关闭弹框事件
      closeDialog() {
        // 关闭弹框的时候清空数据
        if (this.$refs.inStockForm) {
          this.$refs.inStockForm.resetFields();
        }
        if (this.$refs.editInStockForm) {
          this.$refs.editInStockForm.resetFields();
        }
        this.inStockForm = this.$options.data().inStockForm;
        this.inStockBillDetailList = this.$options.data().inStockBillDetailList;
      },
      // 关闭拒绝原因事件
      closeCancelDialog() {
        if (this.$refs.cancelForm) {
          this.$refs.cancelForm.resetFields();
        }
        this.cancelForm = this.$options.data().cancelForm;
      },
    },
  };

</script>
<style lang="scss" scoped>
  .addWuliaoBox {
    padding: 10px 16px;

    .tableBox {
      margin-top: 16px;
      border: 1px solid #e6e6e6;
      border-bottom: none;
      border-radius: 8px 8px 0 0;
      overflow: hidden;

      .tt {
        height: 38px;
        line-height: 38px;
        padding-left: 16px;
        background: #f7f8fa;
        border-radius: 8px 8px 0 0;
      }
    }
  }

  .subTip {
    border-bottom: 1px #e6e6e6 solid;
    background: #f5f6f9;
    padding: 8px 16px;
  }

  .paginaCon.noborder {
    border-top: none;
    text-align: left;

    .pagination-container {
      padding: 0;
    }
  }

  .marDialog {
    height: 100%;

    .btnCon {
      border-bottom: none;
    }
  }

</style>
